/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CastleDefense;

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

//First, get an ImageFilter, as La'ie Techie suggested. You probably want
//something like this:

public class ImageHue extends RGBImageFilter
{
    float ratioR, ratioG, ratioB;

    public ImageHue(Color color)
    {
        ratioR = color.getRed() / 255f;
        ratioG = color.getGreen() / 255f;
        ratioB = color.getBlue() / 140f;
    }

    public int filterRGB(int x, int y, int rgb)
    {
        int
        b = rgb & 0xff,
        g = (rgb >>=8)  & 0xff,
        r = (rgb >>=8)  & 0xff;
        r = (int) Math.round(r * ratioR);
        g = (int) Math.round(g * ratioG);
        b = (int) Math.round(b * ratioB);
        if (r < 0) r = 0; else if (r > 255) r = 255;
        if (g < 0) g = 0; else if (g > 255) g = 255;
        if (b < 0) b = 0; else if (b > 255) b = 255;
        
        return (rgb & 0xff000000) + ((((r <<8)  + g) <<8)  + b);
    }

    /*public static void main(String[] args) throws IOException
    {
        ImageHue imf = new ImageHue(new Color(115,190,234));
        String filename = "C:\\Users\\Administrator\\Documents\\NetBeansProjects\\CastleDefense\\src\\CastleDefense\\sprites\\monsters\\monster_1.PNG";
        Image image = Toolkit.getDefaultToolkit().createImage(filename);
        Image imDst = Toolkit.getDefaultToolkit().createImage(new
                        FilteredImageSource(image.getSource(), imf));

         JFrame frame = new JFrame();
        frame.setVisible(true);
        frame.setSize(imDst.getWidth(null), imDst.getHeight(null));
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.add(new JLabel(new ImageIcon(imDst)));
        frame.pack();

    }*/
}

